let line = "Corona(Trump)USA<<<Virus";
line = line.split("");
let length = line.length;
let res = [];
let flag = 0;
for (let i = 0; i < length; i++) {
  if (line[i] == "<" && res.length) {
    res.pop();
  } else if (line[i] == "(") {
    flag++;
  } else if (line[i] == ")") {
    flag--;
  } else if (flag == 0) {
    res.push(line[i]);
  }
}
res = res.join("");
console.log(res);
